<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主要内容区main</title>
<link href="../include/css/css.css" type="text/css" rel="stylesheet" />
<link href="../include/css/main.css" type="text/css" rel="stylesheet" />
<link rel="shortcut icon" href="../include/images/main/favicon.ico" />
<style>
body{overflow-x:hidden; background:#f2f0f5; padding:15px 0px 10px 5px;}
#searchmain{ font-size:12px;}
#search{ font-size:12px; background:#548fc9; margin:10px 10px 0 0; display:inline; width:100%; color:#FFF; float:left}
#search form span{height:40px; line-height:40px; padding:0 0px 0 10px; float:left;}
#search form input.text-word{height:24px; line-height:24px; width:180px; margin:8px 0 6px 0; padding:0 0px 0 10px; float:left; border:1px solid #FFF;}
#search form input.text-but{height:24px; line-height:24px; width:55px; background:url(../include/images/main/list_input.jpg) no-repeat left top; border:none; cursor:pointer; font-family:"Microsoft YaHei","Tahoma","Arial",'宋体'; color:#666; float:left; margin:8px 0 0 6px; display:inline;}
#search a.add{ background:url(../include/images/main/add.jpg) no-repeat -3px 7px #548fc9; padding:0 10px 0 26px; height:40px; line-height:40px; font-size:14px; font-weight:bold; color:#FFF; float:right}
#search a:hover.add{ text-decoration:underline; color:#d2e9ff;}
#main-tab{ border:1px solid #eaeaea; background:#FFF; font-size:12px;}
#main-tab th{ font-size:12px; background:url(../include/images/main/list_bg.jpg) repeat-x; height:32px; line-height:32px;}
#main-tab td{ font-size:12px; line-height:40px;}
#main-tab td a{ font-size:12px; color:#548fc9;}
#main-tab td a:hover{color:#565656; text-decoration:underline;}
.bordertop{ border-top:1px solid #ebebeb}
.borderright{ border-right:1px solid #ebebeb}
.borderbottom{ border-bottom:1px solid #ebebeb}
.borderleft{ border-left:1px solid #ebebeb}
.gray{ color:#dbdbdb;}
td.fenye{ padding:10px 0 0 0; text-align:right;}
.bggray{ background:#f9f9f9}
</style>
</head>
<body>
<?php error_reporting(E_ALL & ~E_NOTICE);?>
<!--main_top-->
<table width="99%" border="0" cellspacing="0" cellpadding="0" id="searchmain">
  <tr>
    <td width="99%" align="left" valign="top">您的位置：商品管理&nbsp;&nbsp;>&nbsp;&nbsp;查看商品</td>
  </tr>
  <tr>
    <td align="left" valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="search">
  		<tr>
   		 <td width="90%" align="left" valign="middle">
	         <form action="index.php">
			   <span>状态:</span>
                    <select name='state' class="text-word" class="text-but" style="margin:10px 0px">
                        <option value='1' <?php echo $_GET['state']=='1' ? 'selected' : '';?> >新上架</option>
                        <option value='2' <?php echo $_GET['state']=='2' ? 'selected' : '';?> >在售</option>
                        <option value='3' <?php echo $_GET['state']=='3' ? 'selected' : '';?> >已下架</option>
                    </select>		
				 <span>单价：</span>
				 <input style="width:60px; margin-right:10px;" type="text" name="price_1" value="<?php echo $_GET['price_1']; ?>" class="text-word">
				 <input style="width:60px;" type="text" name="price_2" value="<?php echo $_GET['price_2']; ?>" class="text-word">
				 <input type="submit" value="查询" >
	         </form>
         </td>
  		  <td width="10%" align="center" valign="middle" style="text-align:right; width:150px;">
		  <a href="add.php" target="mainFrame" onFocus="this.blur()" class="add" style="marign-right:2px;">新增商品</a></td>
  		</tr>
	</table>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">
    
    <table style="text-align:center;" width="100%" border="0" cellspacing="0" cellpadding="0" id="main-tab">
      <tr>
        <th width=45 align="center" valign="middle" class="borderright">商品ID</th>
        <th align="center" valign="middle" class="borderright">商品类别</th>
        <th align="center" valign="middle" class="borderright">商品名称</th>
        <th align="center" valign="middle" class="borderright">生产厂家</th>
        <th align="center" valign="middle" class="borderright">简介</th>
        <th align="center" valign="middle" class="borderright">单价</th>
        <th width=70 align="center" valign="middle" class="borderright">图片</th>
        <th align="center" valign="middle" class="borderright">状态</th>
        <th align="center" valign="middle" class="borderright">库存量</th>
        <th width=45px align="center" valign="middle" class="borderright">被购量</th>
        <th align="center" valign="middle" class="borderright">点击数</th>
        <th width=130 align="center" valign="middle" class="borderright">添加时间</th>
        <th align="center" valign="middle">操作</th>
      </tr>
      <?php
	date_default_timezone_set("PRC");
	include('../../public/dbconfig.php');
	$link = mysqli_connect(HOST,USER,PASS,DBNAME);
	if(mysqli_connect_errno($link)){
		die('连接数据库失败');
	}
	mysqli_select_db($link,DBNAME);
	mysqli_set_charset($link,'utf8');		
	
	//===========封装搜索条件================
		$state = array("1"=>"新上架","2"=>"在售","3"=>"已下架");
		$wherelist = array();
		$urllsit = array();
		//var_dump($_GET);
		//var_dump(empty($_GET['price_1']));die;
		  if(!empty($_GET['state'])){
                $wherelist[] =" state='{$_GET['state']}'";
                $urllist[] = "state={$_GET['state']}";
            }
		if(!empty($_GET['goods'])){
			$wherelist[] = "goods like '%{$_GET['goods']}%'";
			$urllist[] = "goods={$_GET['goods']}";
		}
		//var_dump($_GET['name']);die;
		//var_dump($_GET['pid']);
		if(!empty($_GET['price_1'])||$_GET['price_1']=='0'){
			$wherelist[] = "price between {$_GET['price_1']}";
			$urllist[] = "price_1={$_GET['price_1']}";
		}
		
		if(!empty($_GET['price_2'])){
			$wherelist[] = "{$_GET['price_2']}";
			$urllist[] = "price_2={$_GET['price_2']}";
		}
		 //echo '<pre>';
		//print_r($wherelist);die;
		
		if(count($wherelist)>0){
			$where = " where ".implode(" and ",$wherelist);
			$url = "&".implode("&",$urllist);
			//echo $where;die;
		}
		
			//=========分页=============
		$_GET['p'] = empty($_GET['p'])?0:$_GET['p']; //页码
		$pageSize = 9; //每页条数
		$maxPage = 0; //页数
		$maxRow = 0; //总条数
			
			//获得总条数 和总页数
		//2 一共有多少条 
		$sql = "select * from goods".$where;
		//echo $sql;die;
		$result = mysqli_query($link,$sql);
		$arr = mysqli_fetch_assoc($result);
		//print_r($arr);die;
		$maxRow = mysqli_num_rows($result);
		//echo $maxRow;
		$maxPage = ceil($maxRow/$pageSize);
		//echo $maxPage;die;
		//判断页码
		//4 判断页码 
		if($_GET['p']>$maxPage){
			$_GET['p'] = $maxPage;
		}
		if($_GET['p']<1){
			$_GET['p']=1;
		}	
		$limit = " limit ".($_GET['p']-1)*$pageSize.",".$pageSize;
			
		
		//echo $sql;die;
		$sql = "select * from goods".$where.$limit;
		//echo $sql;
		$result = mysqli_query($link,$sql);
		while($list = mysqli_fetch_assoc($result)){
				$sql_3 = "select * from type where id={$list['typeid']}";
			//echo $sql_3;die;
			$result_3 = mysqli_query($link,$sql_3);
			$brr = mysqli_fetch_assoc($result_3);
			echo '<tr>';
				echo "<td>".$list['id']."</td>"; 
				echo "<td>".$list['typeid']."</td>"; 
				echo "<td>".$list['goods']."</td>"; 
				echo "<td>".$list['company']."</td>"; 
				echo "<td>".$list['descr']."</td>"; 
				echo "<td>".$list['price']."</td>"; 
				echo "<td><a href='../../public/uploads/{$list['picname']}'><img src='../../public/uploads/s_{$list['picname']}'></a></td>";
				echo "<td>".$state[$list['state']]."</td>"; 
				echo "<td>".$list['store']."</td>"; 
				echo "<td>".$list['num']."</td>"; 
				echo "<td>".$list['clicknum']."</td>"; 
				echo "<td>".date('Y-m-d H:i:s',$list['addtime'])."</td>"; 
				echo "<td>
					<a href='edit.php?id={$list['id']}&filename={$list['picname']}'>修改</a>
					<a href='action.php?action=del&id={$list['id']}&filename={$list['picname']}'>删除</a>
				</td>";
			echo '</tr>';
		} 
	
	mysqli_free_result($result);
	mysqli_close($link);
	
	
?>

    </table></td>
    </tr>
  <tr>
    <td align="left" valign="top" class="fenye"><?php echo $maxRow." 条数据 ".$_GET['p']."/".$maxPage." 页";?>&nbsp;&nbsp;<a href="index.php?p=1<?php echo $url;?>" target="mainFrame" onFocus="this.blur()">首页</a>&nbsp;&nbsp;<a href="index.php?p=<?php echo ($_GET['p']-1).$url;?>" target="mainFrame" onFocus="this.blur()">上一页</a>&nbsp;&nbsp;<a href="index.php?p=<?php echo ($_GET['p']+1).$url;?>" target="mainFrame" onFocus="this.blur()">下一页</a>&nbsp;&nbsp;<a href="index.php?p=<?php echo $maxPage.$url;?>" target="mainFrame" onFocus="this.blur()">尾页</a></td>
  </tr>
</table>
<?php
	$_GET['errno'] = empty($_GET['errno'])?0:$_GET['errno'];
	switch($_GET['errno']){
		case 1:
		echo "<h2 style={color:red;}>删除失败</h2>";
		break;
	}
?>
</body>
</html>